﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EllenTang.IDal;
using System.Configuration;
using System.Reflection;
namespace EllenTang.DalFactory
{
    public class AbstractFactory
    {
        //配置文件中引入的命名空间
        static readonly string NameSpace = ConfigurationManager.AppSettings["NameSpace"];

        /// <summary>
        /// 获取AccessStatisticsDal的实例
        /// </summary>
        /// <returns>AccessStatisticsDal转为接口</returns>
        public static IAccessStatistics GetAccessAccessStatisticsDal()
        {
            string FullName = NameSpace + ".AccessStatisticsDal";
            return CreateInstance(FullName) as IAccessStatistics;
        }

        /// <summary>
        /// 获取AccessTableDal的实例
        /// </summary>
        /// <returns>AccessTableDal转为接口</returns>
        public static IAccessTable GetAccessTableDal()
        {
            string fullName = NameSpace + ".AccessTableDal";
            return CreateInstance(fullName) as IAccessTable;
        }

        /// <summary>
        /// 获取类的实例
        /// </summary>
        /// <param name="fullName">类的命名空间</param>
        /// <returns>类的实例</returns>
        public static object CreateInstance(string fullName)
        {
            var assembly = Assembly.Load(NameSpace);
            return assembly.CreateInstance(fullName);
        }
    }
}
